package com.hxd.otc.dialog;

import android.content.Context;
import android.support.annotation.StringRes;
import android.view.View;
import android.widget.TextView;

import com.flyco.dialog.widget.base.BaseDialog;
import com.hxd.otc.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by lzy on 2018/7/24 0024.
 * description ${确认删除对话框 钱包地址}
 */
public class ConfirmDeleteDialog extends BaseDialog<ConfirmDeleteDialog> {
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.tv_cancel)
    TextView mTvCancel;
    @BindView(R.id.tv_confirm)
    TextView mTvConfirm;

    private CharSequence title;


    public ConfirmDeleteDialog(Context context) {
        super(context);
    }

    @Override
    public View onCreateView() {
        widthScale(0.67f);
        return View.inflate(getContext(), R.layout.dialog_confirm, null);
    }

    @Override
    public void onViewCreated(View view) {
        ButterKnife.bind(this, view);
    }

    @Override
    public void setUiBeforShow() {
        mTvTitle.setText(title);
    }


    @OnClick({R.id.tv_cancel, R.id.tv_confirm})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_confirm:
                if (onConfirmClickListener != null) {
                    onConfirmClickListener.onConfirm();
                }
                break;
        }
        dismiss();
    }

    private OnConfirmClickListener onConfirmClickListener;

    public ConfirmDeleteDialog setOnConfirmClickListener(OnConfirmClickListener onConfirmClickListener) {
        this.onConfirmClickListener = onConfirmClickListener;
        return this;
    }

    public interface OnConfirmClickListener {
        void onConfirm();
    }

    public ConfirmDeleteDialog setTitleText(CharSequence title) {
        this.title = title;
        return this;
    }

    public ConfirmDeleteDialog setTitleText(@StringRes int resid) {
        setTitleText(getString(resid));
        return this;
    }

    private CharSequence getString(@StringRes int resid) {
        return getContext().getString(resid);
    }
}
